home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / News / Alexandra.0.82 / Source / readline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  700 b   |  37 lines

  1. #import "readline.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. static char *buffer=NULL;
  6. static unsigned long length_of_buffer;
  7.  
  8.  
  9. char *readline(FILE *theFile)
  10. {
  11.     void *ptr;
  12.     int offset;
  13.  
  14.     if(buffer==NULL){
  15.       buffer=(char *)malloc(64*sizeof(char));
  16.       length_of_buffer=64;
  17.     }
  18.     ptr=NULL;
  19.     offset=0;
  20.      *buffer='\0';
  21.     while(ptr=fgets(buffer+offset,length_of_buffer-offset,theFile), ((ptr!=NULL)&&(buffer[strlen(buffer)-1]!='\n'))){
  22.        buffer=realloc((char *)buffer,length_of_buffer*2);
  23.        offset=length_of_buffer-1;
  24.        length_of_buffer*=2;
  25.     }
  26.     
  27.     if(ptr==NULL)
  28.        return NULL;
  29.     else
  30.        return buffer;
  31. }
  32.  
  33. char *get_buffer()
  34. {
  35.    return buffer;
  36. }
  37.